### -*- coding: utf-8 -*- #############################################
# Разработано Паэглит Арвидом (http://arvid.dp.ua/)
# Все права защищены, 2007
#
# Developed by Paeglit Arvid (http://arvid.dp.ua/)
# All right reserved, 2007
#######################################################################

"""Interfaces of diplom

$Id: interfaces.py 76 2008-03-13 03:07:17Z Arvi3D $
"""
__author__  = "Arvid"
__license__ = "GPL"
__version__ = "$Revision: 76 $"
__date__ = "$Date: 2008-03-13 03:07:17 +0000 (Thu, 13 Mar 2008) $"

from zope.interface import Interface, Attribute, invariant, Invalid
from zope.app.container.interfaces import IContainer
from zope import schema
from zope.interface import implements
from zope.app.container.constraints import contains, containers

_ = lambda x : x

class IExperiments(IContainer):
    """folder that contains data for experiments"""
    contains('diplom.interfaces.IDataForExperiment')

class IDataForExperiment(Interface):
    """Data class"""
    containers('diplom.interfaces.IExperiments')

class IVariant(Interface):

    variant = Attribute(_(u"Variant"))

    classCount =  schema.Int(
                           title = _(u"Class count")
                           ,description = _(u"Class count")
                           ,readonly = True
                           ,default = 0
                           )

    front =  schema.Float(
                           title = _(u"Min variant")
                           ,description = _(u"Minimum variant")
                           ,readonly = True
                           ,default = 0.0
                           )

    back =  schema.Float(
                           title = _(u"Max variant")
                           ,description = _(u"Maximum variant")
                           ,readonly = True
                           ,default = 0.0
                           )

    classLength =  schema.Float(
                           title = _(u"Class length")
                           ,description = _(u"Class length")
                           ,readonly = True
                           ,default = 0.0
                           )

    #def regenerateVariant(vector):
    #    """calculate variant and save in attribute variant"""

class ISelection(Interface):
    """interface for selection"""

    vector = schema.Tuple(
                           title = _(u"Vector")
                           ,description = _(u"Selection vector")
                           ,readonly = True
                           ,value_type = schema.Float(title = _(u"Item"))
                           )

    def nu(k):
        """get begin moment"""

    def mu(k):
        """get central moment"""

    mean =  schema.Float(
                           title = _(u"Avarage")
                           ,description = _(u"Avarage")
                           ,readonly = True
                           ,default = 0.0
                           )

    def var(zsuneniy = True):
        """get sqr of square distance"""

    def sigma(zsuneniy = True):
        """get square distance"""

    def eksces(zsuneniy = True):
        """ get eksces"""

    def distributing(x):
        """distributing function based on variant"""

    def closeness(x):
        """closeness function based on variant"""


class IDistributingFactory(Interface):
    """distributing factory"""

    params = Attribute(_(u"Interface of params"))
    constraints = Attribute(_(u"Constraints on params"))

    def generate(**params):
        """generate distributing variate"""

    def distributing(x, **params):
        """ distributing function"""
        return expo_distributing(lambd)(x)

    def closeness(x, **params):
        """closeness function"""

class IGenerated(Interface):

    dimension = schema.Int(
                           title = _(u"Dimension")
                           ,description = _(u"Number of elements")
                           ,default = 100
                           ,min = 50
                           ,readonly = False
                           )

    weight =  schema.Float(
                           title = _(u"Weight")
                           ,description = _(u"Weight of first selection in common selection")
                           ,default = 0.5
                           ,min = 0.0
                           ,max = 1.0
                           ,required = True
                           )

    params = Attribute(_(u"Generated params"))

class IEthalon(Interface):
    """ethalon interface"""

    firstDistr = schema.Choice(title=_(u"First distributing")
                               ,required = True
                               ,vocabulary = "Distributing factories"
                               #,readonly = True
                               )

    secondDistr = schema.Choice(title=_(u"Second distributing")
                               ,required = True
                               ,vocabulary = "Distributing factories"
                               #,readonly = True
                               )

    def teoreticalDistributing(x, weight, paramlist):
        """teoretical distributing function"""

    def teoreticalCloseness(x, weight, paramlist):
        """teoretical closeness function"""


class IGenetic(Interface):

    mutation = schema.Float(
                           title = _(u"Propability of mutation")
                           ,description = _(u"Propability of mutation")
                           ,default = 0.9
                           ,min = 0.0
                           ,max = 1.0
                           ,required = True
                           )

    crossover = schema.Float(
                           title = _(u"Propability of crossover")
                           ,description = _(u"Propability of crossover")
                           ,min = 0.0
                           ,max = 1.0
                           ,default = 0.3
                           ,required = True
                           )

    populationCount = schema.Int(
                           title = _(u"Population count")
                           ,description = _(u"Population count")
                           ,min = 50
                           ,default = 100
                           ,required = True
                           )

    generation = schema.Int(
                           title = _(u"Generation count")
                           ,description = _(u"Generation count")
                           ,min = 1
                           ,default = 100
                           ,required = True
                           )

    best = schema.TextLine(
                           title = _(u"Best parameters")
                           ,description = _(u"Best parameters")
                           ,required = False
                           ,readonly = True
                           )

    eval = schema.Float(
                           title = _(u"Eval function")
                           ,description = _(u"Eval function")
                           ,required = False
                           ,readonly = True
                           )

    ga = Attribute(""" Result of genetic algorithm """)

    def runAlgorithm(self, data):
        """find optimum and save in attribute ga"""

